package com.zcn.io.web.service;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcn.io.common.util.DateUtil;
import com.zcn.io.web.api.entity.NegotiateInfo;
import com.zcn.io.web.api.vo.NegotiateInfoVo;
import com.zcn.io.web.auth.LoginUser;
import com.zcn.io.web.mapper.NegotiationMapper;
import lombok.RequiredArgsConstructor;
//import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc:
 * @author: 202438 邱建伟
 * @date: 2025/1/12 11:29
 * @Copyright (c) 2025, 江苏金恒信息科技股份有限公司
 */
@Service
@RequiredArgsConstructor
public class NegotiationService {
    private final NegotiationMapper negotiationMapper;

    public void list(Page<NegotiateInfo> page, NegotiateInfo negotiateInfo) {
        this.negotiationMapper.list(page, negotiateInfo);
    }

    public void save(NegotiateInfo negotiateInfo) {
        negotiateInfo.setLastHandleTime(DateUtil.getDefaultDate());
//        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        if (principal instanceof LoginUser) {
//            negotiateInfo.setLastHandleUser(((LoginUser) principal).getUsername());
//        }
        this.negotiationMapper.insert(negotiateInfo);
    }

    public NegotiateInfo getById(String id) {
        return negotiationMapper.selectById(id);
    }

    public void updateById(NegotiateInfo negotiateInfo) {
        negotiateInfo.setLastHandleTime(DateUtil.getDefaultDate());
//        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        if (principal instanceof LoginUser) {
//            negotiateInfo.setLastHandleUser(((LoginUser) principal).getUsername());
//        }
        negotiationMapper.updateById(negotiateInfo);
    }

    public void deleteById(String id) {
        negotiationMapper.deleteById(id);
    }

    public List<NegotiateInfoVo> listAllByPhoneCode(NegotiateInfo negotiateInfo) {
        return negotiationMapper.listAllByPhoneCode(negotiateInfo);
    }
}
